@extends('layout.master')

@section('title','添加贴子')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
	<link href="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')
    @if (session('message'))
        <div>
            <input type="hidden" id="hidden" name="hidden" value="hidden">
            <input type="hidden" id="message" name="message" value="{{ session('message') }}">
            <input type="hidden" id="status" name="status" value="{{ session('status') }}">
        </div>
    @endif
    <div class="white-box">
        <form class="form-horizontal form-material" method="post" id='formid' enctype="multipart/form-data">
	        <div class="row">
	            <div class="col-md-6 col-sm-4">
                    <div class="form-group">
                        <label class="col-md-12">定时时间</label>
                        <div class="col-md-12">
                            <input type="text" name="push_time" id='datetimepicker2'
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>
			</div>
			<div class="row">	
                <div class="col-md-2 col-sm-4">
                    <label class="control-label">所属圈子</label>
                    <div class="example">
                        <select id="circle_id" name="circle_id">
							@foreach(DB::table('kl_circle_dic')->select('id', 'name')->where('is_del','1')->get() as $value)
                                <option value="{{ $value->id}}">{{ $value->name }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="col-md-2 col-sm-4">
                    <label class="control-label">发布用户名</label>
                    <div class="example">
                        <select id="user_id" name="user_id">
							@foreach(DB::table('t_member')->select('c_id', 'name')->get() as $value)
                                <option value="{{ $value->c_id}}">{{ $value->name }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
				
			</div>
			<div class="row" style="margin-bottom: 17px;">			


                <div class="col-md-2 col-sm-4">
                    <label class="control-label">是否加精</label>
                    <div class="example">
                        <select id="is_excellent" name="is_excellent">
                            @foreach(App\Carticle::$IsexcDisplay as $key => $value)
                                <option value="{{ $key }}">{{ $value }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
			
                <div class="col-md-2 col-sm-4">
                    <label class="control-label">是否删除</label>
                    <div class="example">
                        <select id="is_del" name="is_del">
                            @foreach(App\Carticle::$DelDisplay as $key => $value)
                                <option value="{{ $key }}"  @if( $key==1) selected  @endif>{{ $value }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
				
			</div>	
	
                    <div class="row">
                        <div class="col-lg-2 col-md-2">
                            <div class="row">
                                <label class="control-label">图片/视频</label>
                            </div>
                            <div class="row">
                                <div class="radio radio-purple">
                                    <input type="radio" name="porm" checked id="pic" value="1">
                                    <label for="radio8"> 图片 </label>
                                </div>
                            </div>
                            <div class="row">
                                <div class="radio radio-purple">
                                    <input type="radio" name="porm" id="video" value="2">
                                    <label for="radio8"> 视频 </label>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 col-md-9">
                            <div class="row">
                                <div class="col-lg-4 col-md-4" id="">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-1 file1" class="dropify" name="file1"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4" id="file2">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-2" class="dropify" name="file2"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4" id="file3">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-3" class="dropify" name="file3"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4" id="file4">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-4" class="dropify" name="file4"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4" id="file5">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-5" class="dropify" name="file5"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4" id="file6">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-6" class="dropify" name="file6"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4" id="file7">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-7" class="dropify" name="file7"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4" id="file8">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-8" class="dropify" name="file8"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-md-4" id="file9">
                                    <div class="form-group ">
                                        <input type="file" id="input-file-now-custom-9" class="dropify" name="file9"
                                               data-height="100px"
                                               data-default-file=""/>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
            <div class="row">
				<div class="form-group m-b-40 m-t-10">
					<p for="remarks">内容</p>
					<textarea id="content" name="content" cols="80" rows="5"></textarea>
				</div>
            </div>

        
        <div class="form-group">
            <button type="button" class="fcbtn btn btn-success btn-outline btn-1e waves-effect" id="publish">添加
            </button>

            {!! csrf_field() !!}
            <a class="fcbtn btn btn-info btn-outline btn-1e waves-effect" href="{{ url('/quanzi/list') }}">返回
            </a>
        </div>
	</form>
    </div>

@endsection
@section('js')
    @parent
	 <script src="{{ asset('plugins/bower_components/moment/moment.js') }}"></script>
	<script src="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
    <script>
    function init() {
        //定义locale汉化插件
		$('#datetimepicker2').daterangepicker({
					"autoApply": true,
					"singleDatePicker": true,
					"showDropdowns": true,
				   "timePicker": true,
					"timePicker24Hour": true,
					"startDate": moment().hours(0).minutes(0).seconds(0), //设置开始日期
				   //"opens": "center",
				  // "drops": "up",
					 locale: {
						 format: "YYYY-MM-DD HH:mm:ss",
						   applyLabel: '确定',
						   cancelLabel: '取消',
						   daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
						   monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
							   '七月', '八月', '九月', '十月', '十一月', '十二月'
						   ],
						   firstDay: 1
					 },
		  }, function(start) {
					 console.log(start.format('YYYY-MM-DD HH:mm:ss'));
				 });

        //初始化显示当前时间
       // $('#daterange-btn span').html(moment().subtract('hours', 1).format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD'));

    };
       /* $(document).ready(function () {
            $('#summernote').summernote();
        });
        $('#summernote').summernote({
            height: 500,
            toolbar: [
                // [groupName, [list of button]]
                ['style', ['bold', 'italic', 'underline', 'clear']],
                ['fontsize', ['fontsize']],
                ['fontname', ['fontname']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['height', ['height']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['fullscreen', 'codeview', 'help']]
            ],
            lang: 'zh-CN',
            placeholder: '内容',
            dialogsFade: true,
            callbacks: {
                onImageUpload: function (files) {
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        data: data,
                        type: "POST",
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: "/upload", //填写后台上传文件的路径
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function (url) {//url为上传成功后返回的图片路径
                            var imgNode = document.createElement('img');
                            imgNode.src = url;
                            $('#summernote').summernote('insertNode', imgNode);
                        }
                    })
                }
            }
        });*/
    </script>

    <script>
	    $(document).ready(function () {
			init();
            var hidden = $('#hidden').val();
            if (hidden === 'hidden') {
                if ($('#status').val() == 1) {
                    toastsuccess($('#message').val());
                } else {
                    toasterror($('#message').val());
                }
            }
        });
        $("#publish").click(function (e) {
			//var data = $("#summernote").val();
			//$("#content").html(data);
			var time = $("input[name='push_time']").val();
			var content = $("#content").val();
			
			if(time==''){
				 swal("定时时间不能为空!");
				 return false; 				
			}
			
			if(content==''){
				 swal("帖子内容不能为空!");
				 return false; 
			}
			var len = content.length; 
			if ( len < 5 ) {
				swal("帖子内容不能少为5个字符!");
				return false; 
			}		
			
			document.getElementById("formid").submit();
        });
        $('#pic').click(function () {
            $('#file2').show();
            $('#file3').show();
            $('#file4').show();
            $('#file5').show();
            $('#file6').show();
            $('#file7').show();
            $('#file8').show();
            $('#file9').show();
        });

        $('#video').click(function () {
            $('#file2').hide();
            $('#file3').hide();
            $('#file4').hide();
            $('#file5').hide();
            $('#file6').hide();
            $('#file7').hide();
            $('#file8').hide();
            $('#file9').hide();
        });
    </script>
@endsection